#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N=1e6+10;
//-p<=maxn-k<=p
//-p<=minn-k<=p
//[a[i]-p,a[i]+p]
int main() {

	int n,p;
	cin>>n>>p;
	vector<int> vecArr(N);
	for(int i=0;i<n;++i){
		cin>>vecArr[i];
	}
	sort(vecArr.begin(),vecArr.end());
	int left=0,right=0;
	int nRet=-1;
	
	while(right<n){
		while(left<=right && vecArr[right]-vecArr[left]>2*p){
			++left;
		}
		nRet=max(nRet,right-left+1);
		++right;
	}
	cout<<nRet;
	
	return 0;
}
